<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="/js/jquery-1.12.4.js"></script>
    <script>
        $(function () {
            $("#blogListForm").submit(function () {
                if ($("[name = 'pageNum']").val() > $("#pages").text) {
                    alert("跳转的页面超过了最大页面值");
                    return false;
                }
            })
            //分页
            $("#firstPage").click(function(){//上一页
                var pageIndex = $("[name='pageIndex']").val();
                if (pageIndex==1){
                    return;
                }
                $("[name='pageIndex']").val("1");
                $("#blogListForm").submit();
            });

            $("#prevPage").click(function(){//上一页
                var pageIndex = $("[name='pageIndex']").val();
                pageIndex = parseInt(pageIndex);
                if (pageIndex==1){
                    return;
                }
                $("[name='pageIndex']").val(pageIndex-1);
                $("#blogListForm").submit();
            });

            $("#nextPage").click(function(){//下一页
                var pageIndex = $("[name='pageIndex']").val();
                var count = parseInt($("#count").text());
                pageIndex = parseInt(pageIndex);
                if (pageIndex==count){
                    return;
                }
                $("[name='pageIndex']").val(pageIndex+1);
                $("#blogListForm").submit();
            });

            $("#lastPage").click(function(){//尾页
                var pageIndex = $("[name='pageIndex']").val();
                var count = parseInt($("#count").text());
                pageIndex = parseInt(pageIndex);
                if (pageIndex==count){
                    return;
                }
                $("[name='pageIndex']").val(count);
                $("#blogListForm").submit();
            });
        })
    </script>
</head>
<body>
<h3>${sessionScope.user.nickname}，您好，欢迎访问微博管理系统！&nbsp;&nbsp;&nbsp;<a href="/user/logout.action">注销</a></h3>
    <a href="/user/query.action">去用户界面</a>
    <form action="/blog/query.action" method="post" id="blogListForm">
        <input type="hidden" name="pageIndex" value="${pageInfo.pageNum }"/>
        <table id="tab">
            <c:forEach items="${pageInfo.list}" var="b">
                <tr>
                    <c:forEach items="${userList}" var="u">
                        <c:if test="${b.userid == u.id}">
                            <td><img src="/images/${u.picpath}" width="50px"></td>
                        </c:if>
                    </c:forEach>
                    <td>${b.content}</td>
                    <td><fmt:formatDate value="${b.publishtime}" pattern="yyyy-MM-dd"/></td>
                    <td><a href="/blog/delete.action?id=${b.id}">删除</a></td>
                </tr>
            </c:forEach>
            <tr>
                <td colspan="5" style="background-color:white;">
                    <b>共${pageInfo.total}条记录&nbsp;每页<input type="text" name="pageSize" width="20px">条
                        &nbsp;第${pageInfo.pageNum}页/共<span id="count">${pageInfo.pages}页</span>
                        &nbsp;<a href="javascript:void(0)" id="firstPage">第一页</a>
                        &nbsp;<a href="javascript:void(0)" id="prevPage">上一页</a>
                        &nbsp;<a href="javascript:void(0)" id="nextPage">下一页</a>
                        &nbsp;<a href="javascript:void(0)" id="lastPage">最后一页</a>
                        &nbsp;转到第<input type="text" name="pageNum">页<input type="submit" value="查看">
                    </b>
                </td>
            </tr>
            <tr>
                <td colspan="5">
                    <span style="color: red">${deleteMessage}</span>
                </td>
            </tr>
        </table>
    </form>
<a href="/blog/add.action">发表微博</a>
</body>
</html>
